import axios from 'axios'

export default {
	namespaced: true,
	actions: {
		getPage: function ({commit},params) {
			let {callback} = params;
			params.onget = ({page}) =>{
				callback(page);
			}
			
			commit("getPage",params)
		},
		getAllPage: function ({commit},params) {
			let {callback} = params;
			
			params.onget = ({pages})=>{
				callback(pages);
			}
			
			commit("getAll",params)
		},
        deletePage: function ({commit},params) {
            let {callback} = params;

            params.onget = ({data}) =>{
                callback(data.success);
            }

            commit("deletePage",params)
        },
	},
	mutations: {
		getPage: function (state, {id, onget}) {
			axios.get("/page/" + id).then(({data}) => {
				onget(data);
			});
		},
		getAll: function (state, {title, pageContent, pageTypeId, plateId, userId, page, size, onget}) {
			axios.get('/page',
				{
					params:{
						title,pageContent,pageTypeId,plateId,userId,page,size
					}
				}
			).then(({data}) => {
				onget(data);
			});
		},
        deletePage: function (state, {id, onget}) {
            axios.delete(`/page`,{params:{id}}).then(data => {
                onget(data);
            });
        },
	}
	
}